package com.data.modules.smzh.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.data.common.api.vo.Result;
import com.data.common.constant.enums.ProductEnum;
import com.data.common.system.query.QueryGenerator;
import com.data.common.util.ConvertUtils;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.data.modules.smzh.entity.SmDeviceVersion;
import com.data.modules.smzh.service.ISmDeviceVersionService;
import lombok.extern.slf4j.Slf4j;

import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import com.data.common.system.base.controller.BootController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.data.common.aspect.annotation.AutoLog;

 /**
 * @Description: 设备版本信息
 * @Author: data-boot
 * @Date:   2023-03-23
 * @Version: V1.0
 */
@Api(tags="设备版本信息")
@RestController
@RequestMapping("/smzh/smDeviceVersion")
@Slf4j
public class SmDeviceVersionController extends BootController<SmDeviceVersion, ISmDeviceVersionService> {
	@Autowired
	private ISmDeviceVersionService smDeviceVersionService;

	/**
	 * 分页列表查询
	 *
	 * @param smDeviceVersion
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@ApiOperation(value="设备版本信息-分页列表查询", notes="设备版本信息-分页列表查询")
	@GetMapping(value = "/list")
	public Result<?> queryPageList(SmDeviceVersion smDeviceVersion,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<SmDeviceVersion> queryWrapper = QueryGenerator.initQueryWrapper(smDeviceVersion, req.getParameterMap());
		queryWrapper.ne("model","SMW-GDXW");
		Page<SmDeviceVersion> page = new Page<SmDeviceVersion>(pageNo, pageSize);
		IPage<SmDeviceVersion> pageList = smDeviceVersionService.page(page, queryWrapper);
		//多线程组装 项目名称

		return Result.OK(pageList);
	}

	 @ApiOperation(value="设备版本信息-分页列表查询", notes="设备版本信息-分页列表查询")
	 @GetMapping(value = "/gdlist")
	 public Result<?> queryPageListByGd(SmDeviceVersion smDeviceVersion,
									@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
									@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
									HttpServletRequest req) {
		// smDeviceVersion.setModel(ProductEnum.SMW_GDXW.getCode());
		 ArrayList<String> models = new ArrayList<>();
		 models.add(ProductEnum.SMW_GDXW.getCode());
		 models.add(ProductEnum.SMW_BDXW.getCode());
		 QueryWrapper<SmDeviceVersion> queryWrapper = QueryGenerator.initQueryWrapper(smDeviceVersion, req.getParameterMap());
		 queryWrapper.in("model",models);
		 Page<SmDeviceVersion> page = new Page<SmDeviceVersion>(pageNo, pageSize);
		 IPage<SmDeviceVersion> pageList = smDeviceVersionService.page(page, queryWrapper);
		 //多线程组装 项目名称
		 return Result.OK(pageList);
	 }

	/**
	 *   添加
	 *
	 * @param smDeviceVersion
	 * @return
	 */
	@ApiOperation(value="设备版本信息-添加", notes="设备版本信息-添加")
	@PostMapping(value = "/add")
	public Result<?> add(@RequestBody SmDeviceVersion smDeviceVersion) {
		smDeviceVersionService.save(smDeviceVersion);
		return Result.OK("添加成功！");
	}


	/**
	 *  编辑
	 *
	 * @param smDeviceVersion
	 * @return
	 */
	@ApiOperation(value="设备版本信息-编辑", notes="设备版本信息-编辑")
	@PutMapping(value = "/edit")
	public Result<?> edit(@RequestBody SmDeviceVersion smDeviceVersion) {
		smDeviceVersionService.updateById(smDeviceVersion);
		return Result.OK("编辑成功!");
	}

	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@ApiOperation(value="设备版本信息-通过id删除", notes="设备版本信息-通过id删除")
	@DeleteMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name="id",required=true) String id) {
		smDeviceVersionService.removeById(id);
		return Result.OK("删除成功!");
	}

	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@ApiOperation(value="设备版本信息-批量删除", notes="设备版本信息-批量删除")
	@DeleteMapping(value = "/deleteBatch")
	public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.smDeviceVersionService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}

	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	@ApiOperation(value="设备版本信息-通过id查询", notes="设备版本信息-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
		SmDeviceVersion smDeviceVersion = smDeviceVersionService.getById(id);
		if(smDeviceVersion==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(smDeviceVersion);
	}

    /**
    * 导出excel
    *
    * @param request
    * @param smDeviceVersion
    */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, SmDeviceVersion smDeviceVersion) {
        return super.exportXls(request, smDeviceVersion, SmDeviceVersion.class, "设备版本信息");
    }

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, SmDeviceVersion.class);
    }

}
